var canvasPainter;
var saveDrawing;
var canvasAnimator;
var colorWidget;
var lineWidthWidget;
var transportWidget;
var imageRecNo;
var solidColor = true;

function doInit() {	
  if(CanvasHelper.canvasExists("canvas")) {
    var canvasElem = document.getElementById("canvas");
    canvasPainter = new CanvasPainter("canvas", "canvasInterface", {x: canvasElem.offsetLeft, y: canvasElem.offsetTop}, {w: canvasElem.width, h: canvasElem.height});
    //init save objects
    saveDrawing = new CPDrawing(canvasPainter);
    canvasPainter.image.onload = function() {
      saveDrawing.paintDrawing();
    }
    canvasPainter.image.src = "/images/"+imageRecNo+";showfile";
    makeColorSelectors();
  } else {
  }
}
function setCPDrawAction(action) {
  canvasPainter.setDrawAction(action);
}
function sendDrawings() {
  var drawings = saveDrawing.drawing;
  var str = Object.toJSON(drawings);
  new Ajax.Request("/images/save_image/"+imageRecNo, {
    asynchronous:true,
    evalScripts:true,
    parameters: {data: str},
  });
}
function updateColor() {
  elem = document.getElementById('color_picker')
  if (elem)
    canvasPainter.setColor(elem.value);
}
function setSolidColor(solid) {
  solidColor = solid;
  elem = document.getElementById("color_picker_input");
  elem.value = solid ? canvasPainter.drawColor : canvasPainter.fillColor;
  inputBoxUpdated();
}
